<template>
    <div>
        <h1>病房信息录入</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>病房号</td>
                    <td>
                        <input type="text" v-model="data.Rnumber">
                    </td>
                </tr>
                <tr>
                    <td>RNname</td>
                    <td>
                        <input type="text" v-model="data.RNname">
                    </td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="data.Ksid">
                            <option value="0">科室</option>
                            <option v-for="d in xiala" :value="d.DMid">{{ d.DMname }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>床位总数量</td>
                    <td>
                        <input type="number" v-model="data.bednum">
                    </td>
                </tr>
                <tr>
                    <td>空闲床数量</td>
                    <td>
                        <input type="number" v-model="data.nobednum">
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td>
                        <input type="date" v-model="data.Rtimes">
                    </td>
                </tr>
                
                <tr>
                    
                    <td><input type="button" value="添加" class="btn btn-success" @click="tianj()"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';

onMounted(() => {
   KSXL(); 
});
const data = ref({
  "Rid": 0,
  "Rnumber": "",
  "Ksid": 0,
  "bednum": null,
  "states": 0,
  "nobednum": null,
  "Rtimes": "2025-05-19T06:19:13.333Z",
  "RNname": ""
})

const tianj = ()=>{
    if(data.value.RNname=="")
    {
        alert("姓名不能为空");
        return;
    }
    if(data.value.RNname.length>6)
    {
        alert("姓名不能超过6个字符");
        return;
    }
    axios.post("https://localhost:7292/api/Room/AddBF",data.value).then(res=>{
        if(res.data==1)
        {
            alert("添加成功");
            location.href="/ShowBF";
        }
        else
        {
            alert("添加失败");
        }
    })
}

///////科室下拉//////////////
const xiala = ref([
    {
    "DMid": 0,
    "DMname": "",
  }
])
const KSXL = ()=>{
    axios.get("https://localhost:7292/api/Deparment/daoc").then(res=>{
        xiala.value=res.data
    })
}
</script>

<style scoped>

</style>